package com.dwxt.mall.admin.service;

import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.StatusCode;
import com.dwxt.mall.dao.MallIndexMapper;
import com.dwxt.mall.entity.MallIndex;
import com.dwxt.mall.entity.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallIndexServiceAdmin {
    @Autowired
    private MallIndexMapper mallIndexMapper;

    public void delete(Integer id) {
        mallIndexMapper.deleteByPrimaryKey(id);
    }

    public BaseResult createOrUpdateIndex(MallIndex mallIndex) {
        if (mallIndex.getId() == null) {
            try {
                mallIndexMapper.insertSelective(mallIndex);
            } catch (Exception e) {
                return BaseResult.build(StatusCode.REPEAT_PRODUCT);
            }
        } else {
            mallIndexMapper.updateByPrimaryKeySelective(mallIndex);
        }
        return BaseResult.ok();
    }
}
